﻿@model GetCase
           @{
               ViewBag.Title = "แก้ไขเรื่องร้องเรียน";
           }
@using (Html.BeginForm("EditCase", "GroupList", FormMethod.Post, new {id = "form1111"}))
{
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
    SelectList severities = ViewBag.severities;
    SelectList listPriorities = ViewBag.listPriorities;
    SelectList secrets = ViewBag.secrets;
    

    <!-- keep id -->
    <input name="case_id" type="hidden" value="@Model.case_id" />
    <input name="date_opened" type="hidden" value="@Model.date_opened" />
    <input name="date_closed" type="hidden" value="@Model.date_closed" />
    <input name="channel_incoming_id" type="hidden" value="@Model.channel_incoming_id" />
    <input name="call_back" type="hidden" value="@Model.call_back" />
    <input name="channel_outgoing_id" type="hidden" value="@Model.channel_outgoing_id" />
    <input name="remark" type="hidden" value="@Model.remark" />
    <input name="is_secret" type="hidden" value="@(Model.is_secret ?? "F")" />
    <input name="case_value" type="hidden" value="0" />

    <!-- form start -->
    <div id="servicePageBody" class="servicePage1-action">
        <div id="servicePage-title" >
            <span style="color: rgb(0, 138, 211)"> @Multi.CaseCode :</span>
            @Model.case_code @(Model.date_opened == null ? "" : "(" + Model.date_opened.Value.ToString("dd /MM /yyyy") + ")") 
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            @*<span style="color: rgb(0, 138, 211)"> ผู้เดือดร้อน </span>*@
        </div>
       
        @if (ViewBag.SuccessResult != null)
        {
            <div style="color: green; font-size: 20px; border: solid 1px green; background-color: azure; margin: 10px 10px 10px 10px; padding: 10px 10px 10px 10px">
                @ViewBag.SuccessResult
            </div>
        }
        
        @if (ViewBag.ErrorResult != null)
        {
            <div style="color: red; font-size: 20px; border: solid 1px red; background-color: rgb(250, 191, 171); margin: 10px 10px 10px 10px; padding: 10px 10px 10px 10px">
                @ViewBag.ErrorResult
            </div>
        } 

        <div class="servicePageBox">
            <div id="servicePage4" class="servicePage">
                <table>
                    <tr>
                        <td class="blue">
                            @Multi.Objective_text
                        </td>
                        <td>
                            <a href="@Url.Action("LovCaseObjective", "Complaint")?a=objective_id"
                               data-block="objective_id" class="formBtn2 dBlock">วัตถุประสงค์</a>
                            <span id="block_objective_id">
                                @if (!string.IsNullOrWhiteSpace(Model.objective_id))
                                {
                                    <input type="hidden" name="objective_id" value="@Model.objective_id" />
                                    <div class="blockReAction" data-value="@Model.objective_id">
                                        @Model.objective_text<span onclick=" removebox('objective_id', '@Model.objective_id'); "></span>
                                    </div>
                                }
                            </span>
                        </td>
                        <td rowspan="3" colspan="2" class="tdBottom" style="width: 50%">
                            @Multi.SummarySubject<br />
                            <textarea name="topic" id="summary" name="summary">@Model.summary</textarea>
                        </td>
                    </tr>
                    <tr>
                        <td>@Multi.CaseType</td>
                        <td>
                            <a href="@Url.Action("LovCaseType", "Complaint")?a=type_id" 
                               data-block="type_id" class="formBtn3 dBlock">ประเภทเรื่อง</a>
                            <span id="block_type">
                                @if (!string.IsNullOrWhiteSpace(Model.type_id))
                                {
                                    <input type="hidden" name="type_id" value="@Model.type_id" />
                                    <div class="blockReAction" data-value="@Model.type_id">
                                        @Model.type_text<span onclick=" removebox('type_id', @Model.type_id); "></span>
                                    </div>
                                }
                            </span>
                        </td>
                    </tr>
                   @* <tr>
                        <td>@Multi.CaseTerminalType</td>
                        <td>
                            <a href="@Url.Action("lovcaseterminaltype", "Complaint")?a=terminal_type_id"
                               data-block="terminal_type_id" class="formBtn2 dBlock">@Multi.CaseTerminalType</a>
                            <span id="block_terminal_type_id">
                                @if (!string.IsNullOrWhiteSpace(Model.terminal_type_id))
                                {
                                    <input type="hidden" name="terminal_type_id" value="@Model.terminal_type_id" />
                                    <div class="blockReAction" data-value="@Model.terminal_type_id">
                                        @WSL.GetCaseTerminalType(Model.case_id, Model.terminal_type_id).Select(o => o.text).FirstOrDefault()
                                        <span onclick=" removebox('terminal_type_id', @Model.terminal_type_id); "></span>
                                    </div>
                                }
                            </span>
                        </td>
                    </tr>*@
                    <tr>
                        <td>@Multi.CaseTypeOrgOwne</td>
                        <td>
                            <a href="@Url.Action("LovOrganization2", "Complaint")?a=org_owner" 
                               data-block="organizatoin" class="formBtn3 dBlock">
                                @Multi.AddCaseTypeOrgOwne
                            </a>
                            <span id="block_organizatoin">
                                @foreach (var case_org_owner in Model.list_case_org_owner)
                                {
                                    <input type="hidden" name="list_case_org_owner" value="@case_org_owner.org_id" />
                                    <div class="blockReAction" data-value="@case_org_owner.org_id">
                                        @case_org_owner.org_text<span onclick=" removebox('obj', @case_org_owner.org_id); "></span>
                                    </div>
                                }
                            </span>
                        </td>
                    </tr>
                    <tr>
                        <td>@Multi.used_inform_with</td>
                        <td>
                            <input type="text" class="full-text" id="" value="@Model.org_text" readonly/>
                        </td>
                        <td rowspan="7" colspan="2" class="tdBottom" style="width: 50%">
                            @Multi.Detail_of_Case
                            <textarea id="detail" name="detail">@Model.detail</textarea>
                        </td>
                    </tr>
                    <tr>
                        <td>@Multi.defendent</td>
                        <td>
                            <input type="text" class="full-text" id="defendant" name="defendant" value="@Model.defendant" />
                        </td>
                    </tr>
                    <tr>
                        <td>@Multi.date_occurrenced_from_</td>
                        <td>
                            <input type="text" name="date_occurrenced_from" class="date-input" id="date_occurrenced_from"
                                   value="@(Model.date_occurrenced_from.HasValue ? Model.date_occurrenced_from.Value.ToString("dd/MM/yyyy") : "")" />

                        </td>
                    </tr>
                    <tr>
                        <td>@Multi.date_occurrenced_to_</td>
                        <td>
                            <input type="text" name="date_occurrenced_to" class="date-input" id="date_occurrenced_to"
                                   value="@(Model.date_occurrenced_to.HasValue ? Model.date_occurrenced_to.Value.ToString("dd/MM/yyyy") : "")" />
                        </td>
                    </tr>
                    <tr>
                        <td>@Multi.time_occurrenced</td>
                        <td>
                            <input type="text" name="time_occurrenced" id="time_occurrenced" class="full-text"
                                   value="@Model.time_occurrenced" />
                        </td>
                    </tr>
                    <tr>
                        <td>@Multi.case_area</td>
                        <td>
                            <input type="text" name="timedate-input" class="full-text" id="location" value="@Model.case_area" />
                            <p>@Multi.area</p>
                            <p style="color: gray" id="locationToRedirect">  @Model.province_text @Model.district_text @Model.subdistrict_text 
                                @(string.IsNullOrWhiteSpace(Model.country_id)? "ไทย": 
                                WSL.GetCountry().First(o=>o.val==Model.country_id).text)</p>
                            <input type="hidden" name="country_id" id="country_id" value="@Model.country_id" /> 
                            <input type="hidden" name="province_id" id="province_id" value="@Model.province_id" />
                            <input type="hidden" name="district_id" id="district_id" value="@Model.district_id" />
                            <input type="hidden" name="subdistrict_id" id="subdistrict_id" value="@Model.subdistrict_id" /> 
                            <a href="" data-block="obj" class="formBtnArea dBlock">
                                @Multi.local_scene
                            </a>
                        </td>
                    </tr>
                    <tr>
                        <td>@Multi.postcode</td>
                        <td>
                            <input type="text" name="postcode" class="full-text" id="postcode" value="@Model.postcode" />
                        </td>
                    </tr>
                    <tr>
                        <td>@Multi.map</td>
                        <td>
                            <div id="map_canvas" style="width: 95%; height: 350px;"></div>
                            <input id="lat_value" name="latitude" type="hidden" />
                            <input id="lon_value" name="longitude" type="hidden" />
                        </td>
                        <td colspan="2" class="tdBottom" style="width: 50%">
                            @Multi.reference<br />
                            <textarea name="ref_code" class="half-textarea" id="ref_code" value="@Model.ref_code"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            @Multi.in_court
                        </td>
                        <td>
                            <select name="is_in_court" id="is_in_court">
                                <option value="F" @(Model.is_in_court != "T" ? "selected" : "")>ไม่ใช่</option>
                                <option value="T" @(Model.is_in_court == "T" ? "selected" : "")>ใช่</option>
                            </select>
                        </td>
                        <td colspan="2" class="tdBottom" style="width: 50%">
                            @Multi.status<br />
                            <a href="@Url.Action("LovCaseStatus", "Complaint")?a=status_id"
                               data-block="status_id" class="formBtn2 dBlock">
                                @Multi.operating_status
                            </a>
                            <br />
                            <span id="block_status_id">
                                @if (!string.IsNullOrWhiteSpace(Model.status_id))
                                {
                                    <input type="hidden" name="status_id" value="@Model.status_id" />
                                    <div class="blockReAction" data-value="@Model.status_id">
                                        @Model.status_text
                                        <span onclick="removebox('status_id', '@(Model.status_id)'); ">

                                        </span>
                                    </div>
                                }
                            </span>
                        </td>
                    </tr>
                    <tr>
                        <td>เอกสารแนบ</td>
                        <td>
                            <input type="file" id="case_attachment_input" />
                            <span id="block_case_attachments">
                                @foreach (var ca in Model.list_case_attachment)
                                {
                                            @* 
                                                ด้านล่างคือ sourcecode เวลาเลือกไฟล์ใหม่ แล้ว add เข้ามาผ่าน javascript
                                                <input type="hidden" name="file_content" value=" =" />
                                                <input type="hidden" name="file_description" value="sadf"/>
                                                <input type="hidden" name="doc_type_id" value="1"/>
                                                <input type="hidden" name="doc_no" value="asdfasdf"/>
                                                <input type="hidden" name="doc_date" value="26/05/2558"/>
                                                <input type="hidden" name="doc_ref_no" value="sadf"/>
                                                <input type="hidden" name="doc_ref_date" value="26/05/2558"/>
                                                <input type="hidden" name="file_name" value="26/05/2558"/>
                                                <input type="hidden" name="doc_type" value="I"/>
                                                <div class="blockReAction" id="file_new_attach_1">
                                                    dell_copper_microserver.jpg<span onclick="removeBox1('file_new_attach_1');"></span>
                                                </div>
                                             *@

                                    <!-- ไฟล์เก่า ยังไม่ทราบวิธีดึง content จึงแสดงแต่ชื่อไฟล์ ไม่มีสิ่งให้ post -->
                                    <div class="blockReAction">
                                        @ca.file_name (@(ca.doc_type == "I" ? "รับเข้า" : (ca.doc_type == "O" ? "ส่งออก" : "อื่นๆ")))
                                    </div>

                                }
                            </span>
                        </td>
                        <td rowspan="4" colspan="2" class="tdBottom" style="width: 50%">
                            @Multi.diagnosis_input
                            <textarea name="summary_result" class="half-textarea" id="summary_result">@Model.summary_result</textarea>
                        </td>
                    </tr>
                    <tr>
                        <td>@Multi.severity_id </td>
                        <td class="radio_form">
                            @foreach (var sv in severities) { 
                                <label>
                                    <input type="radio" name="severity_id" class="severity_id" value="@sv.Value" @(Model.severity_id==sv.Value ? " checked=\"checked\"":"") />
                                    @sv.Text
                                </label> 
                            }
                        </td>
                    </tr>
                    <tr>
                        <td>@Multi.secret_id</td>
                        <td class="radio_form">                            
                            @foreach (var sv in secrets)
                            {
                                <label>
                                    <input type="radio" name="secret_id" class="secret_id" value="@sv.Value" @(Model.secret_id == sv.Value ? " checked=\"checked\"" : "") />
                                    @sv.Text
                                </label>
                            }
                        </td>
                    </tr>
                    <tr>
                        <td>@Multi.priority_id</td>
                        <td class="radio_form">
                            @foreach (var sv in listPriorities)
                            {
                                <label>
                                    <input type="radio" name="priority_id" class="priority_id" value="@sv.Value" @(Model.priority_id == sv.Value ? " checked=\"checked\"" : "") />
                                    @sv.Text
                                </label>
                            }
                        </td>
                    </tr>
                </table>
                <div class="boxBlank"></div>
                <div>
                    <a class="BoxServiceActionCancel floatR" href="@Url.Action("Index", "Timeline")" style="color:white">ยกเลิก</a>
                    <input type="submit" class="BoxServiceActionConfirm floatR btnSubmit" value="ยืนยัน" />
                    <div class="clear"></div>
                </div>
            </div>
        </div>
    </div>
}

<script src="~/js/gg_map.js"></script>
<script src="~/js/opm_uploadfile.js"></script>
<script src="~/js/service.js"></script>
<script>
    $('#service_search_table td').click(function (e) {
        parent.returntext = $(this).text();
        parent.returnvalue = $(this).attr('data-return');
        parent.$.colorbox.close();

        e.preventDefault();
        e.stopPropagation();
    });

    function addTextLocation2(locationToRedirect) { 
        $('#locationToRedirect').html(locationToRedirect);
    }
    
    var Lat_val = "@Model.latitude";
    var Lng_val = "@Model.longitude";


    $('.main_menu').height($('#servicePage').height());
</script>


<style>
    .blue {
        color: rgb(148, 148, 255);
    }
</style>